import {reqMyOrderList} from '@/api/index.js';

// 材料：
let state = {
    list: [],
    total: 0,
};

// 加工：
let getters = {

};

// 厨师：
let mutations = {
    SET_LIST(state, value) {
        state.list = value;
    },
    SET_TOTAL(state, value) {
        state.total = value;
    }
};

// 迎宾：
let actions = {
    // 获取我的订单的数据
    async reqMyOrderList({commit, state, dispatch}, {page, limit}) {
        console.log(`Request page number is ${page}, item number is ${limit}`);
        let result = await reqMyOrderList(page, limit);
        console.log(result);
        if (result.code === 200) {
            commit('SET_LIST', result.data.records);
            commit('SET_TOTAL', result.data.total);
            return result;
        } else {
            return Promise.reject(new Error(result.message));
        }
    },
};

// 对外暴露
export default {
    state,
    mutations,
    actions,
    getters
};
